<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>用户管理</title>
	
	<link rel="stylesheet" type="text/css" href="ui/style.css">	
    <link href="ui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="ui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="ui/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="ui/jquery.easyui.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="ui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="ui/common.js"></script>
    <script src="ui/plugins/jquery.watermarkinput.js" type="text/javascript"></script>
	
	<script language="javascript" type="text/javascript">
	    $(document).ready(function () {	
	        $("#grid").datagrid({
	            url: "listUser.action",
	            type: "post",
	            datatype: "json",
	            title:"用户管理",
	            iconCls:"icon-people",
	            border:false,
	            pageSize:20,
	            loadMsg: "数据加载中，请稍后...",
	            fitCloumns: false,
	            nowrap: false,
	            stripe:true,
	            fit: true,//自动大小
	            rownumbers:true,//行号
	            pagination: true,
	            singleSelect: true,
	            toolbar:[{  
			        text:'新增',  
			        iconCls:'icon-add',
			        handler: function() {
                		openDialog("addDialog","add"); 
            		}
			    },'-',{  
			        text:'修改',
			        iconCls:'icon-edit',
			        handler: function() {
                		openDialog("addDialog","edit"); 
            		}
			    },'-',{  
			        text:'删除',  
			        iconCls:'icon-remove',
			        handler: function() {
                		removeUser(); 
            		}  
			    },'-',{  
			        text:'重置密码',  
			        iconCls:'icon-reload',
			        handler: function() {
                		resetPassword(); 
            		}  
			    }]
	        });
	    });
		function resetForm(){
			$( "#addForm" )[ 0 ].reset();
		}
	    function GoEnterPage() {
	        var e = jQuery.Event("keydown");
	        e.keyCode = 13;
	        $("input.pagination-num").trigger(e);
	    }	    
	    function openDialog(dialog,act){
	    	if(act=='add'){
		    	$('#'+dialog).dialog('open').dialog('setTitle','添加用户');  
			    //$('#addForm').form('reset');  
			    $( "#addForm" )[ 0 ].reset();
			    url = 'addUser.action'; 
			}
			if(act=='edit'){
				var select = $('#grid').datagrid('getSelected');
				if(select){
					var row = $('#grid').datagrid('getSelected');  
					if (row){  
					    $('#'+dialog).dialog('open').dialog('setTitle','编辑用户');  
					    $('#addForm').form('load',row);  
					    url = 'editUser.action?id='+row.id;  
					}
				}else{
					$.messager.alert('请注意','请选择要编辑的行！','warning');
				}  
			}
	    }
	    function saveUser(){
	    	//alert(url);  
		    $('#addForm').form('submit',{  
		        url: url,  
		        onSubmit: function(){  
		        	//校验表单
		        	//alert("11111");
		        	//alert($('#addForm').form('validate'));
		            return $('#addForm').form('validate');
		        },  
		        success: function(result){
		        	//alert(result);  
		            var result = eval('('+result+')');  
		            if (result.success){ 
		            	$.messager.show({  
		                    title: '信息',  
		                    msg: result.message  
		                }); 
		            	$('#addDialog').dialog('close');      // close the dialog  
		           		$('#grid').datagrid('reload');    // reload the user data  
		            } else {  
		                $.messager.show({  
		                    title: '信息',  
		                    msg: result.message  
		                });
		            }  
		        } 
		    });
		}
		
		function removeUser(){  
		    var row = $('#grid').datagrid('getSelected');  
		    if (row){  
		        $.messager.confirm('确认','确定要删除这条信息吗？',function(r){  
		            if (r){  
		                $.post('removeUser.action',{id:row.id},function(result){ 
		                	//alert(result.success);
		                	
		                    if (result.success){  
		                    	$.messager.show({   // show error message  
		                            title: '信息',  
		                            msg: result.message 
	                            }); 
		                        $('#grid').datagrid('reload');    // reload the user data  		                        
		                    } else {  
		                        $.messager.show({   // show error message  
		                            title: '信息',  
		                            msg: result.message  
		                        });  
		                    }  
		                },'json');  
		            }  
		        });  
		    }else{
				$.messager.alert('请注意','请选择要删除的行！','warning');
			}			 
		}
		function resetPassword(){  
		    var row = $('#grid').datagrid('getSelected');  
		    if (row){  
		        $.messager.confirm('确认','确定要重置密码吗？',function(r){  
		            if (r){  
		                $.post('resetUser.action',{id:row.id},function(result){ 
		                	//alert(result.success);
		                	
		                    if (result.success){  
		                    	$.messager.show({   // show error message  
		                            title: '信息',  
		                            msg: result.message 
	                            }); 
		                        $('#grid').datagrid('reload');    // reload the user data  		                        
		                    } else {  
		                        $.messager.show({   // show error message  
		                            title: '信息',  
		                            msg: result.message  
		                        });  
		                    }  
		                },'json');  
		            }  
		        });  
		    }else{
				$.messager.alert('请注意','请选择要重置密码的用户！','warning');
			}			 
		}
	</script>
	
  </head>
  
  <body runat="server">
    <table id="grid">
    	<thead>  
	        <tr>  
	            <th field="username" width="100">帐号</th>
	            <th field="name" width="100">姓名</th>  
	            <th field="dw" width="200">单位</th>  
	            <th field="department" width="200">部门</th>  
	            <th field="role" width="100">权限</th>  
	        </tr>  
	    </thead>
    </table>  
    <div id="addDialog" class="easyui-dialog" style="width:450px;height:200px;padding:10px 10px;overflow:hidden;margin:auto"  
        closed="true" buttons="#dlg-buttons"> 
	    <form id="addForm" method="post">  
	    	<table width="400px" border="0"  cellpadding="0" cellspacing="0">
	    	  <tr>
	    	  	<td width="15%" height="30px"><div align="right"> <font color="red">*</font><label>帐号：</label></div></td>
	    	  	<td width="30%">
	    	  		<input type="text" name="username" style="width:90%" class="easyui-validatebox" required="true">
	    	  	</td>
	    	  	<td width="15%" height="30px"><div align="right"> <font color="red">*</font><label>姓名：</label></div></td>
	    	  	<td width="30%">
	    	  		<input type="text" name="name" style="width:90%" class="easyui-validatebox" required="true">
	    	  	</td>
	    	  	
	    	  </tr>
	    	  <tr>
	    	  	<td width="15%" height="30px"><div align="right"> <font color="red">*</font><label>单位：</label></div></td>
	    	  	<td width="30%">
	    	  		<select name="dw" style="width:90%" class="easyui-validatebox" required="true">
			    		<option value="" selected="selected">请选择</option>
			    		<option>盐城分公司</option>
			    		<option>亭湖区区局</option>
			    		<option>盐都区区局</option>
			    		<option>东台分公司</option>
			    		<option>大丰分公司</option>
			    		<option>射阳分公司</option>
			    		<option>建湖分公司</option>
			    		<option>阜宁分公司</option>
			    		<option>滨海分公司</option>
			    		<option>响水分公司</option>			    	
			    	</select>
	    	  	</td>
	    	  	<td width="15%" height="30px"><div align="right"> <font color="red">*</font><label>部门：</label></div></td>
	    	  	<td width="30%">
	    	  		<input type="text" name="department" style="width:90%" class="easyui-validatebox" required="true">
	    	  	</td>
	    	  </tr>
	    	  <tr>
	    	  	<td width="15%" height="30px"><div align="right"> <font color="red">*</font><label>权限：</label></div></td>
	    	  	<td width="30%">
	    	  		<select name="role" style="width:90%" class="easyui-validatebox" required="true">
			    		<option value="" selected="selected">请选择</option>
			    		<option value="全区">全区</option>
			    		<option value="市区">市区</option>
			    		<option value="亭湖">亭湖</option>
			    		<option value="盐都">盐都</option>
			    		<option value="东台">东台</option>
			    		<option value="大丰">大丰</option>
			    		<option value="射阳">射阳</option>
			    		<option value="建湖">建湖</option>
			    		<option value="阜宁">阜宁</option>
			    		<option value="滨海">滨海</option>
			    		<option value="响水">响水</option>
			    	</select>
	    	  	</td>
	    	  	<td width="15%" height="30px">&nbsp;</td>
	    	  	<td width="30%">&nbsp;</td>
	    	  </tr>
	    	  <tr>
			  	<td colspan="4" align="right" height="30px"><font color="red">*为必填项,帐号请填入英文或汉语拼音</font></td>
			  </tr>
	    	</table>
	    </form>  
	</div>  
	<div id="dlg-buttons">    
	    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="javascript:resetForm();return false;">重置</a> 
	    <a href="#" id="btnSave" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser();return false;">保存</a> 
	</div>
	
  </body>
</html>
